﻿using Microsoft.AspNetCore.Mvc.Filters;

namespace SmartCity.BasicData.Api.Write.Filters
{
    /// <summary>
    /// 1.实现接口
    /// 2.在实现方法里记录异常内容
    /// 3.把异常处理标记为已处理
    /// </summary>
    public class ScExceptionFilter : IExceptionFilter
    {
        /// <summary>
        /// 日志组件字段
        /// </summary>
        private readonly ILogger<ScExceptionFilter> logger;

        //日志
        public ScExceptionFilter(ILogger<ScExceptionFilter> logger)
        {
            this.logger = logger;
        }
        public void OnException(ExceptionContext context)
        {
            logger.LogError("捕获到一个未处理的全局异常:"+context.Exception.Message);
            context.ExceptionHandled = true;
            //throw new NotImplementedException();
        }
    }
}
